home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / infosrvr / dev / scott / WWW / NextStep / Implementation / old / TcpAccess.m < prev    next >
Text File  |  1992-11-24  |  2KB  |  106 lines

  1. //                                TcpAccess.m
  2.  
  3. // A HyperAccess object provides access to hyperinformation, using particular
  4. //    protocols and data format transformations. This one provides access to
  5. //    the CERNVM FIND system using HTTP/TCP.
  6.  
  7. // History:
  8. //    26 Sep 90    Written TBL
  9.  
  10.  
  11. #import "TcpAccess.h"
  12. #import "Anchor.h"
  13. #import "HTUtils.h"
  14. #import "HTTP.h"
  15.  
  16. /*    Module parameters:
  17. **    -----------------
  18. **
  19. **  These may be undefined and redefined by syspec.h
  20. */
  21.  
  22. @implementation TcpAccess
  23.  
  24. //    Return the name of the access
  25. //    -----------------------------
  26.  
  27. - (const char *)name
  28. {
  29.     return "http";
  30. }
  31.  
  32. //    Open or search  by name
  33. //    -----------------------
  34.     
  35. - accessName:(const char *)arg
  36.     anchor:(Anchor *)anAnchor
  37.     diagnostic:(int)diagnostic
  38. {
  39.     HyperText *    HT;            // the new hypertext
  40.     NXStream * sgmlStream;        // Input stream for marked up hypertext
  41.     int s;                // Socket number for returned data 
  42.  
  43. /* Get node name:
  44. */
  45.     
  46. //    Make a hypertext object with an anchor list.
  47.         
  48.     HT = [HyperText newAnchor:anAnchor Server:self];
  49.  
  50.     [HT setupWindow];            
  51.     [[HT window]setTitle:"Connecting..."];    /* Tell user something's happening */
  52.     [HT setEditable:NO];            /* This is read-only data */
  53.  
  54. //    Now, let's get a stream setup up from the server for the sgml data:
  55.         
  56.     s = HTTP_Get(arg);
  57.     if (s<0) return nil;    /* Failed .. error will be reported by HTTP_get */
  58.     sgmlStream = NXOpenFile(s, NX_READONLY);
  59.  
  60.     if (diagnostic == 2) {            /* Can read the SGML straight */
  61.     [HT readText:sgmlStream];
  62.     return HT;
  63.     }
  64.  
  65. //    Now we parse the SGML
  66.  
  67.     [[HT window]setTitle:"Loading..."];    /* Tell user something's happening */
  68.     [HT readSGML:sgmlStream diagnostic:diagnostic];    
  69.     
  70. //    Clean up now it's on the screen:
  71.     
  72.     if (TRACE) printf("Closing streams\n");
  73.     NXClose(sgmlStream);
  74.     close(s);
  75.  
  76.     return HT;
  77. }
  78.  
  79. //        Actions:
  80.  
  81.  
  82.  
  83. //    This will load an anchor which has a name
  84. //
  85. // On entry,
  86. //    Anchor's address is valid.
  87. // On exit:
  88. //    If there is no success, nil is returned.
  89. //    Otherwise, the anchor is returned.
  90. //
  91.  
  92. - loadAnchor: (Anchor *) a Diagnostic:(int)diagnostic
  93. {
  94.     HyperText * HT;
  95.  
  96.     if ([a node]) {
  97.         return a;        /* Already loaded */
  98.     } else {
  99.         HT = [self accessName:[a address] anchor:a diagnostic:diagnostic];
  100.         if (!HT) return nil;
  101.     return a;
  102.     }
  103. }
  104.  
  105. @end
  106.